//
//  BaseModel.m
//  NuNu
//
//  Created by dllo on 16/1/23.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        /** 在初始化过程中直接给Model赋值KVC */
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

+ (instancetype)baseModelWithDic:(NSDictionary *)dic {
    /** [self class] 本类，子类执行父类方法时代表子类 */
    return [[[[self class] alloc] initWithDic:dic] autorelease];;
}

+ (NSMutableArray *)baseModelHandelWithArray:(NSArray *)array {
    /** 创建Model数组 */
    NSMutableArray *modelArr = [NSMutableArray array];
    /** 遍历字典 */
    for (NSDictionary *dic in array) {
        /** 用字典创建和赋值本类Model */
        id model = [[self class] baseModelWithDic:dic];
        /** 添加到数组中 */
        [modelArr addObject:model];
    }
    /** 返回可变数组 */
    return modelArr;
}

/** 当model的属性中没有和字典的key值相匹配时，进入这个方法 */
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)valueForUndefinedKey:(NSString *)key {
    [super valueForUndefinedKey:key];
    
    return nil;
}

// 通知，观察者移除，代理置空，属性是否
- (void)dealloc {
    [super dealloc];
}


@end
